<?php

namespace app\service;


use app\model\PartnerLogModel;
use app\model\PartnerUserModel;
use app\model\XlBillManagementModel;
use think\facade\Db;

/**
 * tms账单管理
 */
class XlBillManagementService
{
    public static function info($id)
    {
        return XlBillManagementModel::info($id);
    }

    public static function lists($param)
    {
        return XlBillManagementModel::lists($param);
    }

    public static function add($data, $logParam)
    {
        Db::startTrans();
        $data['add_time'] = getNowDateTime();
        $data['update_time'] = getNowDateTime();
        $data['down_start_time'] = getNowDateTime();
        $data['down_end_time'] = getNowDateTime();

        $res = XlBillManagementModel::add($data);
        $dataLog = [
            'partner_user_id' => $logParam['uid'],
            'log_type' => 2,
            'request_ip' => $logParam['ip'],
            'add_time' => getNowDateTime(),
            'log_desc' => '添加tms账单管理',
            'status' => 1,
            'partner_id' => $data['partner_id']
        ];
        
        if ($res ) {
            Db::commit();
            return 10000;
        } else {
            // 回滚事务
            Db::rollback();
            return 10003;
        }
    }

    public static function edit($data, $logParam, $id)
    {


        Db::startTrans();
        $data['update_time'] = getNowDateTime();
        $res = XlBillManagementModel::edit($data, $id);
        $dataLog = [
            'partner_user_id' => $logParam['uid'],
            'log_type' => 2,
            'request_ip' => $logParam['ip'],
            'add_time' => getNowDateTime(),
            'log_desc' => '修改tms账单管理',
            'status' => 1,
            'partner_id' => $data['partner_id']
        ];
        
        if ($res ) {
            Db::commit();
            return 10000;
        } else {
            // 回滚事务
            Db::rollback();

            return 10003;
        }
    }

    public static function del($data, $logParam, $id)
    {


        Db::startTrans();
        $res = XlBillManagementModel::del($id);
        $dataLog = [
            'partner_user_id' => $logParam['uid'],
            'log_type' => 2,
            'request_ip' => $logParam['ip'],
            'add_time' => getNowDateTime(),
            'log_desc' => '删除tms账单管理',
            'status' => 1,
            'partner_id' => $data['partner_id']
        ];
        
        if ($res ) {
            Db::commit();
            return 10000;
        } else {
            // 回滚事务
            Db::rollback();
            return 10003;
        }
    }
}